package bitwiseOperation;

//https://leetcode.cn/problems/counting-bits/description/
public class l_338 {
    public int[] countBits(int n) {
        int[] ans = new int[n + 1];
        for(int i = 0; i <= n; i++)
        {
            int x = i, res = 0;
            while(x != 0)
            {
                x = x & (x - 1);
                res++;
            }
            ans[i] = res;
        }
        return ans;
    }
}
